package com.tulingxueyuan.mall.modules.pms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.common.api.CommonPage;
import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.modules.pms.model.PmsBrand;
import com.tulingxueyuan.mall.modules.pms.service.PmsBrandService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author XuShu
 * @since 2023-05-08/
 */
@RestController
@RequestMapping("/brand")
public class PmsBrandController {
    @Resource
    private PmsBrandService pmsBrandService;

    @ApiOperation("获取分类列表包括children")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage> list(
            @RequestParam(value = "keyword",required = false) String keyword,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "5") Integer pageSize){
        Page page = pmsBrandService.listPage(keyword,pageNum,pageSize);
        CommonPage commonPage = CommonPage.restPage(page);
        return CommonResult.success(commonPage);
    }

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @ApiOperation("根据id查询商品品牌")
    @GetMapping(value = "/{id}")
    public CommonResult<PmsBrand> getById(@PathVariable Long id){
        PmsBrand pmsBrand = pmsBrandService.getById(id);
        return CommonResult.success(pmsBrand);
    }

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @ApiOperation("修改品牌id")
    @PostMapping(value = "/update/{id}")
    public CommonResult update(@PathVariable Long id,@RequestBody PmsBrand brand){
        boolean b = pmsBrandService.updateById(brand);
        if (b){
            return CommonResult.success(b);
        }else {
            return CommonResult.failed();
        }
    }
    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @ApiOperation("删除品牌")
    @PostMapping(value = "/delete/{id}")
    public CommonResult delete(@PathVariable Long id){
        boolean b = pmsBrandService.removeById(id);
        if (b){
            return CommonResult.success(b);
        }else {
            return CommonResult.failed();
        }
    }

    /**
     * 根据id修改是否显示状态商
     * @param
     * @return
     */
    @ApiOperation("删除品牌")
    @PostMapping(value = "/update/factoryStatus")
    public CommonResult updateFactoryStatus(@RequestParam("ids") List<Long> ids,Long factoryStatus){
        boolean b = pmsBrandService.updateStatus(ids,"factory_status",factoryStatus);
        if (b){
            return CommonResult.success(b);
        }else {
            return CommonResult.failed();
        }
    }

    /**
     * 根据id修改是否显示状态商
     * @param
     * @return
     */
    @ApiOperation("删除品牌")
    @PostMapping(value = "/update/showStatus")
    public CommonResult updateShowStatus(@RequestParam("ids") List<Long> ids,Long factoryStatus){
        boolean b = pmsBrandService.updateStatus(ids,"show_status",factoryStatus);
        if (b){
            return CommonResult.success(b);
        }else {
            return CommonResult.failed();
        }
    }
}

